//
//  CYTabbarController.m
//  ToyotaUccn
//
//  Created by 车音 on 2019/10/23.
//  Copyright © 2019 CheYin. All rights reserved.
//

#import "CYTabbarController.h"
#import "NavigationController.h"
#import "CYLoveCarViewController.h"


@interface CYTabbarController () <UITabBarControllerDelegate>

@end

@implementation CYTabbarController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor  whiteColor];
    self.delegate = self;

    [self initTabbarSubview];
        
    
    
    //067BBB   666666
    // iOS13 以下
    UITabBarItem *item = [UITabBarItem appearance];
    [item setTitleTextAttributes:@{ NSForegroundColorAttributeName:[UIColor colorWithHex:0x666666]} forState:UIControlStateNormal];
    [item setTitleTextAttributes:@{ NSForegroundColorAttributeName:[UIColor colorWithHex:0x067BBB]} forState:UIControlStateSelected];
    
    // 方式三：适配iOS13
    if (@available(iOS 13.0, *)) {
        // iOS13 及以上
        self.tabBar.tintColor = [UIColor colorWithHex:0x067BBB];
        self.tabBar.unselectedItemTintColor = [UIColor colorWithHex:0x666666];
    } 
    
 
}

- (void)initTabbarSubview {
   

    ///< 爱车----北明
    CYLoveCarViewController *loveCarVc = [CYLoveCarViewController new];
    loveCarVc.title = @"TOYOTA";

   
    
   
    NavigationController *loveCarNav = [[NavigationController alloc] initWithRootViewController:loveCarVc];
    
    self.viewControllers = @[loveCarNav];
    
    ///< 2.修改标签栏的渲染颜色
    self.tabBar.barTintColor  = [UIColor whiteColor];
    self.tabBar.tintColor = [UIColor blackColor];
    
    ///< 3.设置默认视图控制器
    self.selectedViewController = loveCarNav;
    self.tabBar.backgroundColor = [UIColor hexChangeFloat:@"#FFFFFF"];
    self.delegate = self;
    
    

}

#pragma mark 代理方法
///< 将要开始自定义标签视图控制器所管理的多个视图控制器时触发,点击edit时
- (void)tabBarController:(UITabBarController *)tabBarController willBeginCustomizingViewControllers:(NSArray *)viewControllers {
    NSLog(@"%s %d", __FUNCTION__, __LINE__);
    NSLog(@"%@", viewControllers);
}


///< 结束自定义标签视图控制器所管理的多个视图控制器时触发.点击done时
- (void)tabBarController:(UITabBarController *)tabBarController didEndCustomizingViewControllers:(NSArray *)viewControllers changed:(BOOL)changed {
    NSLog(@"%s %d",__FUNCTION__,__LINE__);
    NSLog(@"%@ \n  %d", viewControllers, changed);
}




- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
    
    UIViewController *selectedViewController = tabBarController.selectedViewController;
    if (selectedViewController == viewController) {
        return NO;
    } else {
        return YES;
    }
}



- (BOOL)shouldAutorotate {
    return NO;
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}


@end

